<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="120px">
      ID：{{ this.$route.params.id }}
      <el-form-item label="爬取地址" prop="fundUrl">
        <el-input v-model="form.fundUrl" />
      </el-form-item>
      <el-form-item label="基金代码" prop="fundCode">
        <el-input v-model="form.fundCode" />
      </el-form-item>
      <el-form-item label="基金名称" prop="fundName">
        <el-input v-model="form.fundName" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">编辑</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { get, update } from '@/api/fundSource'

export default {
  data() {
    return {
      form: {
        id: null,
        fundUrl: null,
        fundCode: null,
        fundName: null
      }
    }
  },
  created() {
    this.fetchDataById()
  },
  methods: {
    fetchDataById() {
      var vm = this
      var id = this.$route.params.id
      get(id).then(function(resp) {
        vm.form = resp.data
      })
    },
    onSubmit() {
      var vm = this
      var id = this.$route.params.id
      var source = vm.form
      update(id, source).then(response => {
        var msg = response.message
        vm.$message.success(msg)
        this.$router.go(-1)
      })
    },
    onCancel() {
      // this.$store.dispatch('delVisitedViews', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

